﻿using PSI.Models.TMS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PSI.Services.TMS {
    public class FeeService : PSIBaseService {
        public List<FeeCntInConsignation> GetInConsignationFeeCnt(string id) {
            var result = new List<FeeCntInConsignation>();

            var sql = @"
                select b.id, a.f_vsl, a.f_voy_num, a.f_clients, b.f_cnt_num,
                    b.f_cnt_type, b.f_cnt_owner, b.f_address, 
                    b.f_goods, b.f_goods_owner, b.f_goods_owner_tel,
                    b.f_unload_man, b.f_unload_man_tel, b.f_bl_number
                from tms_in_consignation a, tms_in_consignation_detail b
                where a.id = b.parent_id and a.id = @id
                ";
            var p = CreateDbParameters();
            p.AddWithValue("id", id);
            Query(sql, p, reader => {
                var fc = new FeeCntInConsignation {
                    Id = reader.GetString(0),
                    Vsl = reader.GetString(1),
                    Clients = reader.GetString(3),
                    CntNumber = reader.GetString(4),
                    CntType = reader.GetString(5),
                    CntOwner = reader.GetString(6),
                    Address = reader.GetString(7),
                    Goods = reader.GetString(8),
                    GoodsOwner = reader.GetString(9),
                    GoodsOwnerTel = reader.GetString(10),
                    UnloadMan = reader.GetString(11),
                    UnloadManTel = reader.GetString(12),
                    BlNumber = reader.GetString(13)
                };
                if (!reader.IsDBNull(2)) {
                    fc.Vsl += "/" + reader.GetString(2);
                }

                result.Add(fc);
            });
            return result;
        }
    }
}